/**
 * @Author : andy.wangzhh
 * @Timestamp : 2016-06-10
 */
var app = sm("do_App");
var page = sm("do_Page");
var hashdata = mm("do_HashData");
var common = require("common");
var nf = sm("do_Notification");
var http = require("helper/http");
var urlUser = require("url/user");
var userUtil = require("helper/user");
var root = ui("$");
page.on("back", function() {
    app.closePage()
});

var headerAout = ui("headerAout");
var addheader = headerAout.add("header", "source://view/reuse/header.ui", 0, 0);

var headerLeft = ui(addheader+".headerLeft");
headerLeft.on("touch", function() {
    app.closePage()
});

var header = ui("header");
header.bindData(hashdata);
hashdata.addData({
    "labelTitle" : "修改密码"
})
header.refreshData();

var layoutForm = ui("layoutForm");
var layoutBtn = ui("layoutBtn");

var addBtnLogin = layoutBtn.add("btnLogin", "source://view/reuse/button.ui",0,0);
var btnLogin = ui("btnLogin");
btnLogin.bindData(hashdata);
hashdata.addData({
    "btnText" : "确定修改"
});
btnLogin.refreshData();

var addRepassword = layoutForm.add("repassword", "source://view/reuse/textField.ui",0,0);
var repassword = ui("repassword");
repassword.bindData(hashdata);
hashdata.addData({
	"textFieldPassword" : true,
    "textFieldHint" : "再确认输入"
});
repassword.refreshData();

var addpassword = layoutForm.add("password", "source://view/reuse/textField.ui",0,0);
var password = ui("password");
password.bindData(hashdata);
hashdata.addData({
	"textFieldPassword" : true,
    "textFieldHint" : "输入新密码"
});
password.refreshData();

var addVerifycode = layoutBtn.add("btnVerifycode", "source://view/reuse/textFieldButton.ui",0,0);
var btnVerifycode = ui("btnVerifycode");
var btnButton = ui(addVerifycode+".button");
var alayoutButton=ui(addVerifycode+".alayoutButton");
btnButton.width=135;
alayoutButton.width=180;
alayoutButton.redraw();
btnButton.redraw();
btnVerifycode.bindData(hashdata);
hashdata.addData({
	"textFieldPassword" : false,
    "textFieldHint" : "输入验证码"
});
btnVerifycode.refreshData();

btnVerifycode.on("touch", function(data,e){
	http.post(urlUser.url.verifycode.addChangePasswordCode,{}, function(data) {
		nf.toast(data.userVerifycodeTips);
	});
});

btnLogin.on("touch", function(data,e){
	var repwdValue = ui(addRepassword+".textField").text;
	var pwdValue = ui(addpassword+".textField").text;
	var verifycodeValue = ui(addVerifycode+".textField").text;
	var tips = [];
	if(repwdValue.trim()===""){
		tips.push("确认密码不能为空");
	}
	if(pwdValue.trim()===""){
		tips.push("新密码不能为空");
	}
	if(verifycodeValue.trim()===""){
		tips.push("验证码不能为空");
	}
	if(tips.length!=0){
		nf.alert(tips.join("\n"));
		return;
	}
	if(pwdValue.trim()!==repwdValue.trim()){
		nf.alert("两次输入的密码不一致");
		return;
	}
	http.post(urlUser.url.login.doChangePwd,{"password":pwdValue,"verifycode":verifycodeValue},function(data){
		nf.toast("密码修改成功");
		app.closePage();
	});
});
//点击背景隐藏输入键盘
root.on("touch",function(){
	page.hideKeyboard();
})